package com.lingxu.base.system.dict.controller;

import com.lingxu.base.common.api.vo.Result;
import com.lingxu.base.system.dict.entity.DictSearch;
import com.lingxu.base.system.dict.entity.SysDict;
import com.lingxu.base.system.dict.entity.SysDictItem;
import com.lingxu.base.system.dict.service.SystemDictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

@Api(tags = "统一支撑数据字典")
@Slf4j
@Validated
@RestController
@RequestMapping("/systemDict")
public class SystemDictController {

    @Autowired
    private SystemDictService sysDictService;

    @ApiOperation("查询数据字典类别列表")
    @RequestMapping(value = "/findSysCodeList",method = RequestMethod.POST)
    public Result findSysDictList(@RequestBody DictSearch dictSearch){
        Integer pageNo = dictSearch.getPageNo();
        Integer pageSize = dictSearch.getPageSize();
        String keyWord=dictSearch.getKeyWord();
        return sysDictService.findSysDictList(pageNo, pageSize,keyWord);
    }

    @ApiOperation("查询数据字典详情列表")
    @RequestMapping(value = "/findSysDictItemList",method = RequestMethod.GET)
    public Result findSysDictItemList(@RequestParam(name="dictid")@ApiParam(value = "字典id",required = true) String dictid){
        return sysDictService.findSysDictItemList(dictid);
    }

    @ApiOperation("新增数据字典类别列表")
    @RequestMapping(value = "/addSysDict",method = RequestMethod.POST)
    public Result addSysDict(@RequestBody SysDict sysDict){
        return sysDictService.addSysDict(sysDict);
    }

    @ApiOperation("新增字典详情")
    @RequestMapping(value = "/addSysDictItem",method = RequestMethod.POST)
    public Result addSysDictItem(@RequestBody SysDictItem sysDictItem){
        return sysDictService.addSysDictItem(sysDictItem);
    }


    @ApiOperation("修改字典类别")
    @RequestMapping(value = "/updateSysDict",method = RequestMethod.POST)
    public Result updateSysDict(@RequestBody SysDict sysDict){
        return sysDictService.updateSysDict(sysDict);
    }

    @ApiOperation("修改字典详情")
    @RequestMapping(value = "/updateSysDictItem",method = RequestMethod.POST)
    public Result updateSysInfo(@RequestBody SysDictItem sysDictItem){
        return sysDictService.updateSysDictItem(sysDictItem);
    }

    @ApiOperation("删除字典类别")
    @RequestMapping(value = "/deleteSysDict",method = RequestMethod.GET)
    public Result deleteSysDict(@NotNull(message = "参数[ids]不可以为空") String ids){
        return sysDictService.deleteSysDict(ids);
    }
    @ApiOperation("删除字典详情")
    @RequestMapping(value = "/deleteSysCodeInfo",method = RequestMethod.GET)
    public Result deleteSysCodeInfo(@NotNull(message = "参数[ids]不可以为空") String ids){
        return sysDictService.deleteSysDictItem(ids);
    }

    @ApiOperation("查询字典缓存")
    @RequestMapping(value = "/findSystemDictCache",method = RequestMethod.GET)
    public Result findSystemDictCache(){
        return sysDictService.findSystemDictCache("HAPTSysDict");
    }
    @ApiOperation("更新查询字典缓存")
    @RequestMapping(value = "/updateSystemDictCache",method = RequestMethod.GET)
    public Result updateSystemDictCache(){
        return sysDictService.updateSystemDictCache("HAPTSysDict");
    }

    @ApiOperation("查询树形结构字典缓存")
    @RequestMapping(value = "/findSystemDictTree",method = RequestMethod.GET)
    public Result findSystemDictTree(){
        return sysDictService.findSystemDictTree("HAPTSysTreeDict");
    }
    @ApiOperation("更新树形结构字典缓存")
    @RequestMapping(value = "/updateSystemDictTreeCache",method = RequestMethod.GET)
    public Result updateSystemDictTreeCache(){
        return sysDictService.updateSystemDictTreeCache("HAPTSysTreeDict");
    }


}
